<template>
    <div style="margin:200px auto;width:65%;background:white;border-radius:5px;">
        <br/>
        <h1 style="text-align:center;margin:20px 0;">企业管理系统</h1>
        <el-form :model="form" status-icon :rules="rules" ref="ruleForm" label-width="100px" style="width:80%;height:200px;text-align:center;">
            <el-form-item label="用户名" prop="username">
                <el-input type="text" v-model="form.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {

    data(){
        return {
            form:{
                username:null,
                password:null,
            },
            rules:{
                username:[
                    {required:true,trigger:'blur',message:'用户名不能为空'}
                ],
                password:[
                    {required:true,trigger:'blur',message:'密码不能为空'}
                ]
            }
        }
    },
    methods:{
        submitForm(){
            const self = this;
            this.post('/login',this.form).then(resp=>{
               if(resp.status == 200){
                   this.$message.success({
                       message:"登录成功",
                       type:'success',
                       duration:1500,
                   });
                   localStorage.setItem('user-info-key',JSON.stringify(resp.data.user || {}));
                  
                    setTimeout(()=>{
                        this.$router.push({path:'/main',query:{}});
                    },1000);
               } 
            }).catch(e=>{

            });
        },
        resetForm(){

            this.get('/admin/user/allMenuList').then(resp=>{
                console.log(resp);
            }).catch(e=>{
                
            })
        },
    }

}
</script>

<style>


</style>